package com.zzti.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class demo {

    @GetMapping("/index")
    public String index() {
        return "redirect:index.html";
    }

    @GetMapping("/aaa")
    public String index2() {
//        HashMap hm = new HashMap<Object,Object>();
//        hm.put("userId",1);
//        hm.put("username","张三");
//        hm.put("email", "aaaaa");
//        hm.put("status", "1");
//        hm.put("lastLoginTime", "2019-07-06 18:40:34");
//        hm.put("lastLoginTime", "2019-07-06 18:40:34");
//        hm.put("deptId", 1);
//        hm.put("deptName", "开发部");
//        JSONArray jo=new JSONArray();
//        jo.add(0, hm);
//        String result = jo.toJSONString();
//        System.out.println(result);
//        model.addAttribute("entity",result);
        return "redirect:view/user/user-edit.html";
    }

    @RequestMapping("/testaaa")
    @ResponseBody
    public String dqwdsa(Model model) {
        HashMap hm = new HashMap<Object, Object>();
        hm.put("userId", 1);
        hm.put("username", "张三");
        hm.put("email", "aaaaa");
        hm.put("status", "1");
        hm.put("lastLoginTime", "2019-07-06 18:40:34");
        hm.put("lastLoginTime", "2019-07-06 18:40:34");
        hm.put("deptId", 1);
        hm.put("deptName", "开发部");
        HashMap[] hms = new HashMap[1];
        hms[0] = hm;
        JSONObject jo = new JSONObject();
        jo.put("data", hms);
        jo.put("count", 30);
        jo.put("code", 0);
        String result = jo.toJSONString();
        System.out.println(result);
        model.addAttribute("entity", result);
        return result;
    }
}
